package com.lkj.producer;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer_HelloWorld {

    public static void main(String[] args) throws IOException, TimeoutException {

        ConnectionFactory factory = new ConnectionFactory();

        factory.setHost("192.168.1.84");
        factory.setPort(5672);
        factory.setVirtualHost("/lkj");
        factory.setUsername("lkj");
        factory.setPassword("lkj");

        Connection connection = factory.newConnection();

        Channel channel = connection.createChannel();

        channel.queueDeclare("hello_world",true,false,false,null);

        String body = "hello rabbitmq!!!";
        channel.basicPublish("","hello_world",null,body.getBytes());

        channel.close();
        connection.close();
    }
}
